#ifndef POLYNOMIAL_PATH_H
#define POLYNOMIAL_PATH_H

#include "function.h"
#include <vector>

namespace Math
{

class PolynomialFunction : public RealFunction
{
public:
  virtual void PreEval(Real t);
  virtual Real Eval(Real t);
  virtual Real Deriv(Real t);
  virtual Real Deriv2(Real t);

  inline size_t Degree() const { return coeffs.size(); }
  size_t EffectiveDegree() const;
  Real Coefficient(int term) const;
  void SetConstant(Real value);
  void SetLinear(Real a,Real b);  //y = at+b
  void ScaleTime(Real s);
  void OffsetTime(Real off);
  void Add(const PolynomialFunction& a,const PolynomialFunction& b);
  void Sub(const PolynomialFunction& a,const PolynomialFunction& b);
  void Mul(const PolynomialFunction& a,const PolynomialFunction& b);

  bool Read(File& f);
  bool Write(File& f) const;

  std::vector<Real> coeffs;
};

class PolynomialPath : public VectorFunction
{
  virtual void PreEval(Real t);
  virtual void Eval(Real t,Vector& x);
  virtual void Deriv(Real t,Vector& dx);
  virtual void Deriv2(Real t,Vector& ddx);

  inline size_t Degree() const { return coeffs.size(); }
  void SetConstant(const Vector& value);
  void SetLinear(const Vector& a,const Vector& b);  //y=at+b
  void ScaleTime(Real s);
  void OffsetTime(Real off);
  void GetElement(int i,PolynomialFunction& f) const;
  void Add(const PolynomialPath& a,const PolynomialPath& b);
  void Sub(const PolynomialPath& a,const PolynomialPath& b);

  bool Read(File& f);
  bool Write(File& f) const;

  std::vector<Vector> coeffs;
};

} //namespace Math

#endif
